
# 抽象工厂模式
from abc import ABCMeta, abstractmethod

class Shape(metaclass=ABCMeta):
    @abstractmethod
    def draw(self):
        pass

class Circle(Shape):
    def draw(self):
        print("Drawing Circle")

class Rectangle(Shape):
    def draw(self):
        print("Drawing Rectangle")

class ShapeFactory(metaclass=ABCMeta):
    @abstractmethod
    def create_shape(self, shape_type):
        pass

class CircleFactory(ShapeFactory):
    def create_shape(self, shape_type):
        if shape_type == "circle":
            return Circle()
        else:
            return None

class RectangleFactory(ShapeFactory):
    def create_shape(self, shape_type):
        if shape_type == "rectangle":
            return Rectangle()
        else:
            return None

if __name__ == "__main__":
    circle_factory = CircleFactory()
    circle = circle_factory.create_shape("circle")
    circle.draw()

    rectangle_factory = RectangleFactory()
    rectangle = rectangle_factory.create_shape("rectangle")
    rectangle.draw()

